﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>角色管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../../static/css/font.css">
    <link rel="stylesheet" href="../../../static/css/weadmin.css">
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
    <div class="weadmin-nav">
        <span class="layui-breadcrumb" style="visibility: visible;">
            <a href="#">首页</a><span lay-separator="">/</span>
            <a href="#">基础数据设置</a><span lay-separator="">/</span>
            <a><cite>角色管理</cite></a>
        </span>
        <a class="layui-btn layui-btn-sm" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
            <i class="layui-icon" style="line-height:30px">ဂ</i>
        </a>
    </div>
    <div class="weadmin-body">
        <table class="layui-hide" id="roleman" lay-filter="roleman"></table>
    </div>
    <script type="text/html" id="toolbar">
        <div class="layui-btn-container">
            <!--<button class="layui-btn layui-btn-sm" lay-event="delAll"><i class="layui-icon"></i>批量删除</button>--><!--功能没做，先隐藏-->
            <button class="layui-btn layui-btn-sm" lay-event="add"><i class="layui-icon"></i>添加</button>
        </div>
    </script>
    <script id="barDemo" type="text/html">
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </script>
    <script src="../../../lib/layui/layui.js" charset="utf-8"></script>
    <script>
        layui.use(['table', 'laydate', 'jquery', 'layer'], function () {
            var table = layui.table,
                laydate = layui.laydate,
                $ = layui.jquery,
                layer = layui.layer;
            laydate.render({
                elem: '#start',
                trigger: 'click'
            });
            laydate.render({
                elem: '#end',
                trigger: 'click'
            });
            $.support.cors = true;
            $.ajaxSetup({
                cache: false,
                headers: {
                    "userid": JSON.parse(window.localStorage.authInfo).UserId,
                    "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                },
            })
            function showList(data) {
                table.render({
                    elem: '#roleman',
                    cellMinWidth: 80,
                    toolbar: "#toolbar",
                    cols: [
                        [
                            { type: 'checkbox' },
                            { field: 'AutoID', title: 'AutoID', sort: true, hide: true },
                            { field: 'RoleID', title: '角色ID',width:100 },
                            { field: 'RoleName', title: '角色名字',width:200 },
                            { field: 'RoleOrderID', title: '内部序号', hide: true },
                            { fixed: 'right', title: '操作', toolbar: '#barDemo', width: 180 },
                        ]
                    ],
                    data: data,
                    event: true,
                    page: true
                });
            }
            //头工具栏事件
            table.on('toolbar(roleman)', function (obj) {
                var checkStatus = table.checkStatus(obj.config.id);
                switch (obj.event) {
                    case 'delAll':
                        console.log(checkStatus.data);
                        break;
                    case 'add':
                        var add = layer.open({
                            type: 2,
                            title: "角色信息添加",
                            area: ['700px', '450px'],
                            fixed: false, //不固定
                            maxmin: true,
                            content: './role_add.html',
                            end: function () {
                                location.reload();
                            }
                        });
                        layer.full(add);
                        break;
                };
            });
            //监听行工具事件
            table.on('tool(roleman)', function (obj) {
                var data = obj.data;
                if (obj.event === 'del') {
                    layer.confirm('确认删除行吗?', function (index) {
                        var postdata = { "RoleID": data.RoleID };
                        $.post(ApiUrl + 'Role/Del', postdata, function (data) {
                            if (data.StatusCode == 200) {
                                obj.del();
                                layer.msg("删除成功！");
                            } else {
                                layer.msg(data.Info);
                            }
                        });
                        layer.close(index);
                    });
                } else if (obj.event === 'edit') {
                    var edit = layer.open({
                        type: 2,
                        title: "角色信息编辑",
                        area: ['700px', '450px'],
                        fixed: false, //不固定
                        maxmin: true,
                        content: './role_edit.html?AutoID=' + obj.data.AutoID + "&RoleID=" + obj.data.RoleID + " &RoleName=" + obj.data.RoleName + " &RoleOrderID=" + obj.data.RoleOrderID,
                        end: function () {
                            location.reload();
                        }
                    });
                    layer.full(edit);
                }
            });
            $(function () {
                var postdata = { "swhere": "", "startindex": "1", "endindex": "100" }
                $.post(ApiUrl + 'Role/Sel', postdata, function (data) {
                    if (data == null)
                        return '提交错误'
                    if (data.StatusCode == 200) {
                        showList(data.Data);
                    } else {
                        return data.Info;
                    }
                });
            })
        });
    </script>

</body>

</html>